﻿
#pragma once

#include "ECommon.h"
#include "ECore.h"
#include "EMaterial.h"
#include "EObject.h"

namespace Base3D
{
	enum COLLISION_TYPE
	{
        COLLISION_COLLISION,
        COLLISION_IGNORE,
	};

	class EMesh : public EObject
	{
    private:
        //GLuint BufferName;
	public:
		~EMesh() override;

		void setScale(const EVector3D &scale);
		void setPosition(const EVector3D &pos);
		EVector3D getPosition() const;
		void move(const EVector3D &mov);

		// 给定点是否在Mesh的包围盒内, 如果是则返回true, 否则返回false
		EBool intersect(const EVector3D &point);

		void setVisible(EBool visible) { mIsVisible = visible;}
		EBool isVisible() const { return mIsVisible; }

		// 是否需要执行剔除操作
		void setCullFlag(EBool needCull) {mObject->needCull = needCull; }

		// 绕Y轴旋转
		void yaw(EFloat yDegree);
		// 绕Z轴旋转
		void roll(EFloat rDegree);
		// 绕X轴旋转
		void pitch(EFloat pDegree);

		void setCollisionType(COLLISION_TYPE type) { mCollisionType = type; }
		COLLISION_TYPE getCollisionType() const { return mCollisionType; }

		EMaterial *getMaterial(EInt index = 0);
		void setMaterial(EInt index, EString matName);

		EObject4D* getObject() const { return mObject; }
		EInt getPolygonNumber() const { return mPolygonNumber; }
		EInt getVertexNumber() const { return mVertexNumber; }
		EInt getSubMeshNumber() const { return mSubMeshNumber; }

		// 获取各轴的旋转分量, 以角度表示
		EVector3D getRotateVec() const { return mRotate; }

		// 对此模型进行clone, 避免再次读盘读取模型
		EMesh *clone();

	protected:
		friend class ESceneManager;
		EMesh();
		//EMesh(const EString &name, const EString &meshName);

		EObject4D		*mObject;

		EInt			mPolygonNumber;	// 模型多边形个数
		EInt			mVertexNumber;	// 模型顶点数

		EInt			mSubMeshNumber;	// 模型子模型个数

		EVector3D		mRotate;		// 模型各轴的旋转分量

		EBool			mIsVisible;

		COLLISION_TYPE	mCollisionType;
    public:
        EMesh(const EString &name, const EString &meshName);
	};
}